package br.com.sovi.resources.usuario;

import java.util.List;

import org.openinsula.vulcano.orm.command.DaoCommand;
import org.openinsula.vulcano.orm.dao.query.DaoQuery;
import org.openinsula.vulcano.orm.dao.query.builder.DaoSelect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;

import br.com.sovi.persistence.Usuario;

public class GetUsuarioByCnpjEmpresaCommand extends DaoCommand<List<Usuario>> {
	private static final long serialVersionUID = 1L;
	
	private final Logger logger = LoggerFactory.getLogger(getClass());
	
	private String cnpj;
	
	public GetUsuarioByCnpjEmpresaCommand(String cnpj) {
		super();
		this.cnpj = cnpj;
	}

	@Override
	public List<Usuario> execute() {
		if (!StringUtils.hasText(cnpj)) {
			throw new IllegalArgumentException("O CNPJ da empresa não pode ser vazio.");
		}
		
		DaoQuery<Usuario> query = new DaoSelect<Usuario>().all().from(Usuario.class).eq("empresa.cnpj", cnpj).toQuery();
		
		return dao.find(query);
	}
	
}
